package com.knowledgegraph.web.controller.system;

import com.knowledgegraph.common.core.domain.AjaxResult;
import com.knowledgegraph.common.core.domain.entity.SysUser;
import com.knowledgegraph.common.core.page.TableDataInfo;
import com.knowledgegraph.zhongyao.domain.Medicine;
import com.knowledgegraph.zhongyao.domain.Prescription;
import com.knowledgegraph.zhongyao.domain.ciyun;
import com.knowledgegraph.zhongyao.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.knowledgegraph.common.config.RuoYiConfig;
import com.knowledgegraph.common.utils.StringUtils;

import java.util.*;
import java.util.stream.Collectors;

/**
 * 首页
 *
 * @author ruoyi
 */
@RestController
public class SysIndexController {
    @Autowired
    IBingService bingService;
    @Autowired
    IPrescriptionService prescriptionService;
    @Autowired
    IMedicineService medicineService;
    @Autowired
    IIntroduceService introduceService;
    @Autowired
    IYangShengService yangShengService;

    @RequestMapping("/alList")
    public AjaxResult list() {
        int size = prescriptionService.selectPrescriptionList(null).size();
        int size1 = medicineService.selectMedicineList(null).size();
        int size2 = introduceService.selectIntroduceList(null).size();
        int size3 = yangShengService.selectYangShengList(null).size();
        Map<String, Object> newVisitis = new HashMap<>();
        newVisitis.put("value", size);
        Map<String, Object> messages = new HashMap<>();
        messages.put("value", size1);
        Map<String, Object> purchases = new HashMap<>();
        purchases.put("value", size2);
        Map<String, Object> shoppings = new HashMap<>();
        shoppings.put("value", size3);
        Map<String, Object> al = new HashMap<>();
        al.put("newVisitis", newVisitis);
        al.put("purchases", purchases);
        al.put("messages", messages);
        al.put("shoppings", shoppings);
        return AjaxResult.success(al);
    }


    @RequestMapping("/shanList")
    public AjaxResult shanList() {

        List<ciyun> list = bingService.shanList();

        return AjaxResult.success(list);
    }

    @RequestMapping("/ciyunList")
    public AjaxResult ciyunList() {
        List<String> medicne = medicineService.selectMedicineList(null).stream().map(item -> item.getFunction()).collect(Collectors.toList());
        List<String> prescr = prescriptionService.selectPrescriptionList(null).stream().map(item -> item.getFunction()).collect(Collectors.toList());
        medicne.addAll(prescr);
        List<String> list2 = new ArrayList<>();
        List<ciyun> list3 = new ArrayList<>();

        for (String s : medicne) {
            list2.addAll(Arrays.asList(s.split(",|，|。|，")));
        }

        for (int i = 0; i < list2.size(); i++) {
            ciyun ciyun = new ciyun(list2.get(i), String.valueOf(i));
            list3.add(ciyun);
        }
        System.err.println(list3);
        return AjaxResult.success(list3);
    }

    @RequestMapping("/zhuList")
    public AjaxResult zhuList() {
        List<ciyun> list = bingService.zhuList();
        List<String> names = list.stream().map(item -> item.getName()).collect(Collectors.toList());
        List<String> values = list.stream().map(item -> item.getValue()).collect(Collectors.toList());
        Map<String, Object> map = new HashMap<>();
        map.put("names",names);
        map.put("values",values);
        return AjaxResult.success(map);
    }
    /**
     * 系统基础配置
     */
    @Autowired
    private RuoYiConfig ruoyiConfig;

    /**
     * 访问首页，提示语
     */
    @RequestMapping("/")
    public String index() {
        return StringUtils.format("欢迎使用{}后台管理框架，当前版本：v{}，请通过前端地址访问。", ruoyiConfig.getName(), ruoyiConfig.getVersion());
    }
}
